package leetcode;

public class MaxValue {
    public static void main(String[] args) {
        MaxValue maxValue = new MaxValue();
        int n = 9, index = 3, maxSum = 16;
        System.out.println(maxValue.maxValue(n, index, maxSum));
    }

    public int maxValue(int n, int index, int maxSum) {
        // 最大能填的数字
        int max = maxSum - n + 1;
        // 从最大数字开始填
        for (int i = max; i >= 1; i--) {
            int sum = i;
        }
        return 0;
    }

    public boolean isOk(int max, int index, int n, int maxSum) {
        return cal(max, index, n) + cal(max, index, n) - max <= maxSum;
    }

    public long cal(int max, int index, int n) {
        long ans;
        if (max - 1 > index) {
            ans = (long) (index + 1) * max - ((long) max * (max - 1)) / 2;
        } else {
            ans = ((long) max * max) - ((long) max * (max - 1)) / 2 + n - (max + index) + 1;
        }
        return ans - max;
    }
}
